package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.custom.RoundedImageView;
import com.luck.easyfoodbatch.glide.GlideCircleTransform;
import com.luck.easyfoodbatch.mvp.model.EvaluateM;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.luck.easyfoodbatch.util.Tools;
import com.luck.easyfoodbatch.util.XLHRatingBar;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class EvaluationAdapter2 extends RecyclerArrayAdapter<EvaluateM.DataBean> {
    private Context mContext;

    public EvaluationAdapter2(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<EvaluateM.DataBean> {
        RoundedImageView riv_avatar;
        TextView tv_name, tv_time, tv_content;
        XLHRatingBar ratingBar3;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.evaluation_item);
            riv_avatar = $(R.id.riv_avatar);
            tv_name = $(R.id.tv_name);
            tv_time = $(R.id.tv_time);
            tv_content = $(R.id.tv_content);
            ratingBar3 = $(R.id.ratingBar3);
        }

        @Override
        public void setData(EvaluateM.DataBean bean, int position) {
            String uname = bean.getUname();
            String avatar_path = bean.getAvatar_path();
            String content = bean.getContent();
            int shop_star = bean.getShop_star();
            int created_at = bean.getCreated_at();
            if (!Tools.isNull(avatar_path)) {
                Glide.with(mContext)
                        .load(HttpUtil.IMG_BASE_URL + avatar_path)
                        .centerCrop()
                        .placeholder(R.mipmap.loading_4b3)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .transform(new GlideCircleTransform(mContext))
                        .into(riv_avatar);
            } else {
                riv_avatar.setImageResource(R.mipmap.loading_4b3);
            }
            if (!Tools.isNull(uname)) {
                tv_name.setText(uname);
            } else {
                tv_name.setText("");
            }
            if (created_at != 0) {
                tv_time.setText(Tools.SubTime2(created_at + ""));
            } else {
                tv_time.setText("");
            }
            ratingBar3.setCountSelected(shop_star);

            if (!Tools.isNull(content)) {
                tv_content.setText(content);
            } else {
                tv_content.setText("");
            }

        }
    }
}
